--[[
  class: Game.Rule

  Game rule(s).

  Create your own custom game mode with this class.

  You can change the game rules and those changes will be applied immediately without have to restart the server.
]]


--[[
  str: name

  Optional. Name of the game mode.

  Data Type: string::
  Access: Read-Write::
]]
Game.Rule.name


--[[
  str: desc

  Optional. Description of the game mode.

  Data Type: string::
  Access: Read-Write::
]]
Game.Rule.desc


--[[
  table: user

  Table for storing user-made data.

  Data Type: table::
  Access: Read-Write::
]]
Game.Rule.user


--[[
  bool: respawnable

  Enable/Disable player respawn.

  Data Type: bool::
  Access: Read-Write::

  Warnings:
    - Overrides map setting.
]]
Game.Rule.respawnable


--[[
  number: respawnTime

  Player respawn delay time in second unit.

  Data Type: number::
  Range: 0 ~ 60::
  Access: Read-Write::

  Warnings:
    - <Game.Rule.respawnable> is REQUIRED to be enabled.
    - Overrides map setting.
]]
Game.Rule.respawnTime


--[[
  bool: enemyfire

  Allow/Disallow to attack hostile players.

  Data Type: bool::
  Access: Read-Write::

  Warnings:
    - Overrides map setting.
]]
Game.Rule.enemyfire


--[[
  bool: friendlyfire

  Allow/Disallow to attack friendly players.

  Data Type: bool::
  Access: Read-Write::

  Warnings:
    - Overrides map setting.
]]
Game.Rule.friendlyfire


--[[
  bool: breakable

  Enable/Disable map block destruction mode.

  Data Type: bool::
  Access: Read-Write::

  Warnings:
    - Overrides map setting.
]]
Game.Rule.breakable


--[[
  method: Respawn

  Force-respawn all players.

  Access: Read-Only::

  Notes:
    - Moves alive player to available active spawn point(s).
]]
function Game.Rule:Respawn ()


--[[
  method: Win

  End current game round and set given team as winner.

  Access: Read-Only::

  Parameters:
    team - (*int / <Game.TEAM>*) The winner team.
    exit - (*bool / nil*) End the game on the next round (true = Enable)(false = Disable)(nil = true).
]]
function Game.Rule:Win (team, exit)


--[[
  method: CanSave

  Check whether gamesave feature is enabled for current map.

  Access: Read-Only::

  Returns:
    (*bool*) true (Enabled) / false (Disabled).
]]
function Game.Rule:CanSave ()


--[[
  method: SetGameSave

  Store the data into shared's gamesave space with given identity name.

  Please refer to <GameSave API> topic for more details.

  Access: Read-Only::

  Warnings:
    - The current map MUST support game-save feature.
    - [BUG?] Only working in singleplayer (max. player is 1) maps.

  Parameters:
    name  - (*string*) The identity of the data.
    value - (*number / string / bool*) The data to store.

   See Also:
    - <Game.Rule.CanSave>
    - <Game.Player.SetGameSave>
]]
function Game.Rule:SetGameSave (name, value)


--[[
  method: GetGameSave

  Retrieve the data from shared's gamesave space with given identity name.

  Please refer to <GameSave API> topic for more details.

  Access: Read-Only::

  Warnings:
    - The current map MUST support game-save feature.
    - [BUG?] Only working in singleplayer (max. player is 1) maps.

  Parameters:
    name  - (*string*) The identity of the data.

  Returns:
    (*number / string / bool / nil*) The retrieved data (nil = No data).

   See Also:
    - <Game.Rule.CanSave>
    - <Game.Player.GetGameSave>
]]
function Game.Rule:GetGameSave (name)


--[[
  event: OnPlayerConnect

  --- Lua
  function Game.Rule:OnPlayerConnect (player)
  ---

  Called when the player is connected to the server.

  Access: Write-Only::

  Parameters:
    player - (*<Game.Player>*) The player.
]]


--[[
  event: OnPlayerDisconnect

  --- Lua
  function Game.Rule:OnPlayerDisconnect (player)
  ---

  Called when the player is disconnected from the server.

  Access: Write-Only::

  Parameters:
    player - (*<Game.Player>*) The player.
]]


--[[
  event: OnRoundStart

  --- Lua
  function Game.Rule:OnRoundStart ()
  ---

  Called when the new round is initialized.

  Access: Write-Only::
]]


--[[
  event: OnRoundStartFinished

  --- Lua
  function Game.Rule:OnRoundStartFinished ()
  ---

  Called when the current round's freeze time is over

  Access: Write-Only::

  Notes:
    - Recommended to setup map init operations in here.
]]


--[[
  event: OnPlayerSpawn

  --- Lua
  function Game.Rule:OnPlayerSpawn (player)
  ---

  Called when the player is (re)spawned.

  Access: Write-Only::

  Parameters:
    player - (*<Game.Player>*) The player.
]]


--[[
  event: OnPlayerJoiningSpawn

  --- Lua
  function Game.Rule:OnPlayerJoiningSpawn (player)
  ---

  Called when the player is spawned for the first time.

  Access: Write-Only::

  Parameters:
    player - (*<Game.Player>*) The player.
]]


--[[
  event: OnPlayerKilled

  --- Lua
  function Game.Rule:OnPlayerKilled (victim, killer, weapontype, hitbox)
  ---

  Called when the player is killed.

  Access: Write-Only::

  Parameters:
    victim     - (*<Game.Player>*) The victim entity.
    killer     - (*<Game.Player> / nil*) The killer entity (nil = Is not a player).
    weapontype - (*int / <Game.WEAPONTYPE>*) The killer's weapon's category.
    hitbox     - (*int / <Game.HITBOX>*) The victim hitbox got hit.
]]


--[[
  event: OnKilled

  --- Lua
  function Game.Rule:OnKilled (victim, killer)
  ---

  Called when the player or monster is killed.

  Access: Write-Only::

  Parameters:
    victim - (*<Game.Entity>*) The victim entity.
    killer - (*<Game.Entity> / nil*) The killer entity (nil = Not a <Game.Entity> object).
]]


--[[
  event: OnPlayerSignal

  --- Lua
  function Game.Rule:OnPlayerSignal (player, signal)
  ---

  Called when the server received a signal from player via <UI.Signal>.

  Access: Write-Only::

  Parameters:
    player - (*<Game.Player>*) The sender.
    signal - (*int*) The received value.
]]


--[[
  event: OnUpdate

  --- Lua
  function Game.Rule:OnUpdate (time)
  ---

  Called every 0.1 seconds since the game started.

  Access: Write-Only::

  Warnings:
    - Cause server-side lagging if expensive calculations are running in this event.

  Parameters:
    time - (*number*) The game time.

  See Also:
    - <Game.GetTime>
]]


--[[
  event: OnPlayerAttack

  --- Lua
  function Game.Rule:OnPlayerAttack (victim, attacker, damage, weapontype, hitbox)
  ---

  Called when the player is attacked.

  Access: Write-Only::

  Parameters:
    victim     - (*<Game.Player>*) The victim entity.
    attacker   - (*<Game.Player> / nil*) The attacker entity (nil = Is not a player).
    damage     - (*int*) The damage taken by the victim.
    weapontype - (*int / <Game.WEAPONTYPE>*) The attacker's weapon's category.
    hitbox     - (*int / <Game.HITBOX>*) The victim hitbox got hit.

  Returns:
    (*int*) (Optional) Override the given damage by returning the value.
]]


--[[
  event: OnTakeDamage

  --- Lua
  function Game.Rule:OnTakeDamage (victim, attacker, damage, weapontype, hitbox)
  ---

  Called when the player or monster is attacked.

  Access: Write-Only::

  Parameters:
    victim     - (*<Game.Entity>*) The victim entity.
    attacker   - (*<Game.Entity> / nil*) The attacker entity (nil = Not a <Game.Entity> object).
    damage     - (*int*) The damage taken by the victim.
    weapontype - (*int / <Game.WEAPONTYPE>*) The attacker's weapon's category.
    hitbox     - (*int / <Game.HITBOX>*) The victim hitbox got hit.

  Returns:
    (*int*) (Optional) Override the given damage by returning the value.
]]


--[[
  event: CanBuyWeapon

  --- Lua
  function Game.Rule:CanBuyWeapon (player, weaponid)
  ---

  Called when the player is about to buy the weapon.

  Access: Write-Only::

  Warnings:
    - Only <Common.WEAPON> weapons are affected.

  Parameters:
    player   - (*<Game.Player>*) The player.
    weaponid - (*int / <Common.WEAPON>*) The weapon ID.

  Returns:
    (*bool*) (Optional) true (Allow to purchase) / false (Disallow to purchase).
]]


--[[
  event: CanHaveWeaponInHand

  --- Lua
  function Game.Rule:CanHaveWeaponInHand (player, weaponid, weapon)
  ---

  Called when the player is about to deploy the weapon.

  Access: Write-Only::

  Warnings:
    - Only <Common.WEAPON> weapons are affected.

  Parameters:
    player   - (*<Game.Player>*) The player.
    weaponid - (*int / <Common.WEAPON>*) The weapon ID.
    weapon   - (*<Game.Weapon> / nil*) The weapon entity (nil = Not using it).

  Returns:
    (*bool*) (Optional) true (Allow to deploy) / false (Disallow to deploy).
]]


--[[
  event: OnGetWeapon

  --- Lua
  function Game.Rule:OnGetWeapon (player, weaponid, weapon)
  ---

  Called when the player pickup the weapon.

  Access: Write-Only::

  Warnings:
    - Only <Common.WEAPON> weapons are affected.

  Parameters:
    player   - (*<Game.Player>*) The player.
    weaponid - (*int / <Common.WEAPON>*) The weapon ID.
    weapon   - (*<Game.Weapon> / nil*) The weapon entity (nil = Not using it or not a <Common.WEAPON> weapon).
]]


--[[
  event: OnReload

  --- Lua
  function Game.Rule:OnReload (player, weapon, time)
  ---

  Called when the player reload the weapon.

  Access: Write-Only::

  Parameters:
    player - (*<Game.Player>*) The player.
    weapon - (*<Game.Weapon> / nil*) The weapon entity (nil = Not using it or not a <Common.WEAPON> weapon).
    time   - (*number*) Finish reload time.
]]


--[[
  event: OnReloadFinished

  --- Lua
  function Game.Rule:OnReloadFinished (player, weapon)
  ---

  Called when the player finished reloading the weapon.

  Access: Write-Only::

  Parameters:
    player - (*<Game.Player>*) The player.
    weapon - (*<Game.Weapon> / nil*) The weapon entity (nil = Not using it or not a <Common.WEAPON> weapon).
]]


--[[
  event: OnSwitchWeapon

  --- Lua
  function Game.Rule:OnSwitchWeapon (player)
  ---

  Called when the player switched to another weapon.

  Access: Write-Only::

  Parameters:
    player - (*<Game.Player>*) The player.
]]


--[[
  event: OnDeployWeapon

  --- Lua
  function Game.Rule:OnDeployWeapon (player, weapon)
  ---

  Called when the player deploy the weapon.

  Notes:
    - Undocumented in official website.

  Access: Write-Only::

  Parameters:
    player - (*<Game.Player>*) The player.
    weapon - (*<Game.Weapon> / nil*) The weapon entity (nil = Not using it or not a <Common.WEAPON> weapon).
]]


--[[
  event: PostFireWeapon

  --- Lua
  function Game.Rule:PostFireWeapon (player, weapon, time)
  ---

  Called when the player fired the weapon.

  Access: Write-Only::

  Parameters:
    player - (*<Game.Player>*) The player.
    weapon - (*<Game.Weapon> / nil*) The weapon entity (nil = Not using it or not a <Common.WEAPON> weapon).
    time   - (*number*) Next fire time.
]]


--[[
  event: OnReceiveGameSave

  --- Lua
  function Game.Rule:OnReceiveGameSave (player)
  ---

  Called when the gamesave data is loaded from database.

  Access: Write-Only::

  Notes:
    - Removed in official website.

  Warnings:
    - If it has owner, the data is not imported yet.
    - Called before <Game.Rule.OnLoadGameSave> event.

  Parameters:
    player - (*<Game.Player> /  nil*) The owner (nil = Is shared gamesave).
]]


--[[
  event: OnGameSave

  --- Lua
  function Game.Rule:OnGameSave (player)
  ---

  Called when the gamesave data is saved to database.

  Access: Write-Only::

  Parameters:
    player - (*<Game.Player> /  nil*) The owner (nil = Is shared gamesave).
]]


--[[
  event: OnLoadGameSave

  --- Lua
  function Game.Rule:OnLoadGameSave (player)
  ---

  Called when the gamesave data is imported.

  Access: Write-Only::

  Parameters:
    player - (*<Game.Player> /  nil*) The owner (nil = Is shared gamesave).
]]


--[[
  event: OnClearGameSave

  --- Lua
  function Game.Rule:OnClearGameSave (player)
  ---

  Called when player's gamesave data is deleted.

  Access: Write-Only::

  Parameters:
    player - (*<Game.Player>*) The owner.
]]

